package com.ml.doctor.network;

import android.text.TextUtils;

import com.google.gson.reflect.TypeToken;
import com.ml.doctor.CustomApplication;
import com.ml.doctor.bean.LoginBean;
import com.ml.doctor.bean.MyServiceBean;
import com.ml.doctor.bean.UserInfoBean;
import com.ml.doctor.utils.LocalShared;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class NetworkApi {
//    public static final String BasicUrl = "http://118.31.238.207:8080/ZZB/";
    public static final String BasicUrl = "http://120.27.209.227:8080/ZZB/";

    public static final String Login = BasicUrl + "login/docter_login";
    public static final String GetTokenUrl = BasicUrl + "br/seltoken";
    public static final String GetDoctorInfoUrl = BasicUrl + "docter/sel_one_doctor_con";
    public static final String GetDoctorService = BasicUrl + "docter/docter_service";
    public static final String EditDoctorInfoUrl = BasicUrl + "docter/doedit";

    /**
     * 用户登录
     */
    public static void login(String username,String password,NetworkManager.SuccessCallback<LoginBean> listener,NetworkManager.FailedCallback failedCallback){
        Map<String,String> map=new HashMap<>();
        map.put("username",username);
        map.put("password",password);
        NetworkManager.getInstance().postResultClass(Login,map, LoginBean.class,listener,failedCallback);
    }

    public static void getUserInfo(NetworkManager.SuccessCallback<UserInfoBean> listener){
        Map<String,String> map=new HashMap<>();
        map.put("docterid", String.valueOf(LocalShared.getInstance(CustomApplication.getInstance()).getUserId()));
        NetworkManager.getInstance().getResultClass(GetDoctorInfoUrl,map, UserInfoBean.class,listener);
    }

    public static void getQiNiuToken(NetworkManager.SuccessCallback<String> listener){
        NetworkManager.getInstance().getResultString(GetTokenUrl, listener);
    }

    public static void getDoctorService(NetworkManager.SuccessCallback<ArrayList<MyServiceBean>> callback){
        Map<String, String> paramsMap = new HashMap<>();
        paramsMap.put("docterid", String.valueOf(LocalShared.getInstance(CustomApplication.getInstance()).getUserId()));
        paramsMap.put("page", "1");
        paramsMap.put("limit", "1000");
        NetworkManager.getInstance().getResultClass(GetDoctorService, paramsMap, new TypeToken<ArrayList<MyServiceBean>>() {
        }.getType(), callback);
    }

    public static void updateInfo(UserInfoBean infoBean, NetworkManager.SuccessCallback<UserInfoBean> successCallback){
        if (infoBean == null){
            return;
        }
        Map<String, String> map = new HashMap<>();
        map.put("docterid", CustomApplication.getInstance().userId + "");
        map.put("documents", infoBean.documents);
        map.put("card", infoBean.card);
        map.put("hosname", infoBean.hosname);
        map.put("adds", infoBean.adds);
        map.put("duty", infoBean.duty);
        map.put("department", infoBean.department);
        map.put("card", infoBean.card);
        map.put("rankid", String.valueOf(infoBean.rankid));
        map.put("gat", infoBean.gat);
        map.put("pend", String.valueOf(infoBean.pend));
        map.put("pro", infoBean.pro);
        map.put("apply_amount", String.valueOf(infoBean.apply_amount));
        map.put("service_amount", String.valueOf(infoBean.service_amount));
        map.put("docter_photo", String.valueOf(infoBean.docter_photo));
//        map.put("pwd", LocalShared.getInstance(this).getUserId() + "");
        NetworkManager.getInstance().getResultClass(EditDoctorInfoUrl, map, UserInfoBean.class, successCallback);
    }

    public static void updateAvatar(String avatarUrl, NetworkManager.SuccessCallback<UserInfoBean> successCallback){
        if (TextUtils.isEmpty(avatarUrl)){
            return;
        }
        Map<String, String> map = new HashMap<>();
        map.put("docterid", CustomApplication.getInstance().userId + "");
        if (!TextUtils.isEmpty(avatarUrl)){
            map.put("docter_photo", avatarUrl);
        }
        map.put("hosname", "");
        map.put("adds", "");
        map.put("duty", "");
        map.put("department", "");
        map.put("card", "");
        map.put("rankid", "");
        map.put("gat", "");
        map.put("pend", "");
        map.put("pro", "");
        map.put("apply_amount", "");
        map.put("service_amount", "");
        map.put("docter_photo", "");
//        map.put("pwd", LocalShared.getInstance(this).getUserId() + "");
        NetworkManager.getInstance().getResultClass(EditDoctorInfoUrl, map, UserInfoBean.class, successCallback);
    }
}
